package com.yl.student.handler;

import com.yl.student.bean.dto.DataVerifyResponseDto;
import com.yl.student.service.LoginInfoService;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@Slf4j
public class PhoneLoginHandler {
    @Resource
    private LoginInfoService loginInfoService;

    /**
     * 这里设计到Spring对容器的管理，需要将接口的实现类对象添加到容器中
     */

    /**
     * 页面前缀为views，login.jsp在views的直接目录下，所以不需要有前缀
     * @return
     */
    @GetMapping("/phoneLogin")
    /**
     * 不设置@ResponseBody，则会将这个请求当成页面解析
     */
    @ResponseBody
    @Transactional(rollbackOn = {Exception.class})
    public DataVerifyResponseDto phoneLogin(@RequestParam("userId") String userId,
                                            @RequestParam("pwd") String pwd,
                                            @RequestParam("role") String role){
        return loginInfoService.verifyLogin(userId,pwd,role);
    }
}